﻿using UnityEditor;
using System;

namespace Hotfix
{
    /// <summary>
    /// Build Info struct used by ABDataSource to pass needed build data around.
    /// </summary>
    public class XHotfixAssetBundleBuildInfo
    {
        /// <summary>
        /// Directory to place build result
        /// </summary>
        public string outputDirectory;

        /// <summary>
        /// Standard asset bundle build options.
        /// </summary>
        public BuildAssetBundleOptions options;

        /// <summary>
        /// Target platform for build.
        /// </summary>
        public BuildTarget buildTarget;
        
        /// <summary>
        /// Callback for build event.
        /// </summary>
        public Action<string> onBuild;
    }

    /// <summary>
    ///
    /// </summary>
    public interface XHotfixAssetBundleDataSource
    {
        /// <summary>
        /// Name of DataSource. Displayed in menu as "Name (ProvidorName)"
        /// </summary>
        public string Name 
        { get; }

        /// <summary>
        /// Name of provider for DataSource. Displayed in menu as "Name (ProvidorName)"
        /// </summary>
        public string ProviderName
        { get; }
        
        /// <summary>
        /// Signals if this data source can have build target set by tool
        /// </summary>
        bool CanSpecifyBuildTarget { get; }

        /// <summary>
        /// Signals if this data source can have output directory set by tool
        /// </summary>
        bool CanSpecifyBuildOutputDirectory { get; }

        /// <summary>
        /// Signals if this data source can have build options set by tool
        /// </summary>
        bool CanSpecifyBuildOptions { get; }

        /// <summary>
        /// Array of paths in bundle.
        /// </summary>
        string[] GetAssetPathsFromAssetBundle (string assetBundleName);

        /// <summary>
        /// Name of bundle explicitly associated with asset at path.  
        /// </summary>
        string GetAssetBundleName(string assetPath);

        /// <summary>
        /// Name of bundle associated with asset at path.  
        ///  The difference between this and GetAssetBundleName() is for assets unassigned to a bundle, but
        ///  residing inside a folder that is assigned to a bundle.  Those assets will implicitly associate
        ///  with the bundle associated with the parent folder.
        /// </summary>
        string GetImplicitAssetBundleName(string assetPath);

        /// <summary>
        /// Array of asset bundle names in project
        /// </summary>
        string[] GetAllAssetBundleNames();

        /// <summary>
        /// If this data source is read only. 
        ///  If this returns true, much of the Browsers's interface will be disabled (drag&drop, etc.)
        /// </summary>
        bool IsReadOnly();

        /// <summary>
        /// Sets the asset bundle name (and variant) on a given asset
        /// </summary>
        void SetAssetBundleNameAndVariant (string assetPath, string bundleName, string variantName);

        /// <summary>
        /// Clears out any asset bundle names that do not have assets associated with them.
        /// </summary>
        void RemoveUnusedAssetBundleNames();

        /// <summary>
        /// Executes data source's implementation of asset bundle building.
        ///   Called by "build" button in build tab of tool.
        /// </summary>
        bool BuildAssetBundles (XHotfixAssetBundleBuildInfo info);
    }
}
